package ruifeng.zcj.dig.base;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.OnClick;
import ruifeng.zcj.dig.R;
import ruifeng.zcj.dig.ui.view.XViewPager;
import ruifeng.zcj.mybase.base.App;
import ruifeng.zcj.mybase.base.BaseActivity;
/**
 * Created by Administrator on 2016/9/26 0026.
 */
public abstract class DepositFragmentNoTitleActivity extends BaseActivity {
    public static final String KEY_CLASS_NAME = "className";
    public static final String KEY_ARGS = "args";

    @Bind(R.id.view_pager)
    public XViewPager mViewPager;

    public ViewPagerFragmentAdapter mBaseFragmentViewPageAdapter;


    @Override
    public int getLayoutId() {
        return R.layout.activity_home_all;
    }

    @Override
    public void initView() {
        mBaseFragmentViewPageAdapter = new ViewPagerFragmentAdapter(App.getAppContext(), getSupportFragmentManager()) {
            @Override
            public void addPage(ArrayList<String> tabTitles, ArrayList<FragmentInfo> fragmentInfos) {
                DepositFragmentNoTitleActivity.this.addPage(tabTitles, fragmentInfos);
            }
        };

        initContainer(mBaseFragmentViewPageAdapter);
        setScreenPageLimit();
//        onSetupTabAdapter(mBaseFragmentViewPageAdapter);
    }

    public void setScreenPageLimit() {

    }

    protected abstract void addPage(ArrayList<String> tabTitles, ArrayList<FragmentInfo> fragmentInfos);

    public void initContainer(final PagerAdapter pagerAdapter) {
        //mViewPager.setOffscreenPageLimit(limit);// 表示limit个界面之间来回切换都不会重新加载
        if (mViewPager == null) {//这样判断有问题
            mViewPager = (XViewPager) getViewById(R.id.view_pager);
//            mViewPager = (XViewPager) view.findViewById(R.id.view_pager);
        }

       /* new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (mViewPager != null) {
                    mViewPager.setAdapter(pagerAdapter);
                }
            }
        }, 100);*/
        if (mViewPager != null){
            mViewPager.setAdapter(pagerAdapter);
        }
    }

    public void setCurrentItem(int item) {
        if (mViewPager != null){
            mViewPager.setCurrentItem(item, false);
        }
    }

    public int getCurrentItem() {
        return mViewPager.getCurrentItem();
    }


    /**
     * 基类会根据不同的catalog展示相应的数据
     *
     * @param catalog 要显示的数据类别
     * @return
     */
    public Bundle getBundle(String catalog) {
        Bundle bundle = new Bundle();
        bundle.putString("11", catalog);
        return bundle;
    }

    public Bundle getBundle(int newType) {
        Bundle bundle = new Bundle();
        bundle.putInt("11", newType);
        return bundle;
    }
}
